package com.mrtan.service.impl;

import com.mrtan.bean.Inandout;
import com.mrtan.mapper.InandoutMapper;
import com.mrtan.service.InandoutService;
import com.mrtan.vo.OutVO;
import com.mrtan.vo.OutWhereVO;
import com.mrtan.vo.StockInsertVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class InandoutServiceImpl implements InandoutService {
    @Resource
    private InandoutMapper inandoutMapper;

    @Override
    public List<Inandout> selectout(OutWhereVO outWhereVO) {
        List<Inandout> outs = inandoutMapper.selectout(outWhereVO);
        return outs;
    }

    @Override
    public int add(OutVO outVO) {
        int i =0;
        for (Object productInfo : outVO.getProducts()) {
            Map<String, Object> productMap = (Map<String, Object>) productInfo;
            String numberStr = (String) productMap.get("number");
            int number = Integer.parseInt(numberStr);
            int n =inandoutMapper.insertInandOut(outVO.getOrderId(),outVO.getWarehouseId(),(Integer)productMap.get("productId"),number);
            i=n+i;
        }
        return i;
    }

    @Override
    public int upateisinandout(StockInsertVO stockInsertVO) {
        return inandoutMapper.updateinandout(stockInsertVO);
    }
}
